package cn.middle.remote;

import cn.middle.remote.serialization.Serialization;
import cn.middle.remote.serialization.TypeGenericity;

public class Buffer {
	
	private String msgId;

	private byte[] data;
	
	private Serialization serialization;
	
	public Buffer(String msgId,byte[] data,Serialization serialization) {
		this.msgId = msgId;
		this.data = data;
		this.serialization = serialization;
	}

	public String getMsgId() {
		return this.msgId;
	}
	
	/**
	 * 接收的数据转化为
	 * @param <T>
	 * @param t
	 * @return
	 */
	public <T> T to(TypeGenericity<T> t){
		return serialization.decode(data, t);
	}
	
	public String formString() {
		return serialization.decode(data, new TypeGenericity<String>() {});
	}
	
	public byte[] binary() {
		return data;
	}
	
}
